﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DuAnNH.Fd_class;

namespace DuAnNH.Fd_class
{
    class CLs_NhanVien
    {        
        public static DataTable LayDSNhanVien()
        {
            try
            {
                string sql = "select MaNV as 'Mã NV', HoTen as 'Họ Tên', NgaySinh as 'Ngày Sinh', TenDN as 'Tài Khoản',MatKhau as 'Mật Khẩu', Nhom as 'Nhóm' from NhanVien,Nhom where NhanVien.NhomId=Nhom.NhomId ";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static DataTable LayDSNVCBB()
        {
            try
            {
                string sql = "select MaNV,HoTen from NhanVien";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static DataTable KiemTra(string TenDN)
        {
            try
            {
                string sql = "select TenDN from NhanVien where TenDN='" + TenDN + "'";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static DataTable SoLuongNV()
        {
            try
            {
                string sql = "SELECT * from NhanVien";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static DataTable TimNhanVien(string tukhoa)
        {
            try
            {
                string sql = "TimKiemNhanVien N'" + @tukhoa + "'";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static bool ThemNhanVien(string hoten, DateTime ngaysinh, string tendn, string matkhau, string nhomid)
        {
            try
            {
                string sql = "[ThemNV] '" + hoten + "','" + ngaysinh + "','" + tendn + "','" + matkhau + "'," + nhomid;
                SqlCommand com = new SqlCommand(sql, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch { return false; }
        }
        public static bool SuaNhanVien(string manv, string hoten, DateTime ngaysinh, string tendn, string matkhau, string nhomid)
        {
            try
            {
                string sql = "SuaNhanVien " + manv + ",'" + hoten + "','" + ngaysinh + "','" + tendn + "','" + matkhau + "'," + nhomid;
                SqlCommand com = new SqlCommand(sql, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch { return false; }
        }
        public static bool XoaNhanVien(string MaNV)
        {
            try
            {
                string sql = "XoaNV " + MaNV;
                SqlCommand com = new SqlCommand(sql, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch { return false; }
        }
        public static DataTable NhomNV()
        {
            try
            {
                string sql = "select * from Nhom";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch { return null; }
        }
    }
}
